Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This merge request adds integrated subscription support for V2Ray.
There are 4 primary components for subscriptions:
Subscription Manager
Subscription Manager will
ImportSources
from time to time to download subscription documentsSubscription Container
parsing components. The subscription documents will then be converted into individual server definitions.Subscription Converter
.Subscription URLs
Currently 2 kinds of Subscription URL are supported
Subscription Container
Container is the document includes a set of server definitions plus metadata.
There is currently 3 supported containers, all of them are generic containers that does not, on their own, compliant with any subscription specs. Instead, they are the simplest way to capture whatever information contained in a subscription document without verifying schema.
The 3 currently supported container formats are:
newline
separated server definitions.Use
v2ray engineering subscriptionEntriesExtract -input filename
to output a zipped file contains what would be captured by V2Ray's Subscription Container parser.Use
v2ray engineering encodeDataURL -type application/vnd.v2ray.subscription-singular
to generate a dataURL.If you are generating these documents, instead of trying to parse one generated by someone else. You should be aware that V2Ray does not check for schema of formats mentioned. For this reason, a document could by parsed by V2Ray may be rejected by other applications.
Subscription Converter
If the server definition is in V2Ray natively supported outbound format, it will be directly loaded with outbound converter. It is recommended for all service providers to generate their subscription in outbound format so that V2Ray could parse their with predictable result.
Otherwise, if the input is not of native outbound format, the non-native input will be converted with conversion rules. The input will be preprocessed with
AbstractNonNativeLink
info extractor and split up input into many strings that can be referenced with their keys, and then all conversion rules will be tried one by one, until one successfully completed without error.To see what keys and values will be extracted from server definition run:
v2ray engineering nonnativelinkextract
and input server definition into stdin. A sorted key value set will be output to stdout for examination.The converter rules are either embedded into V2Ray or provided by user. The user defined rules always take precedence.
The embedded converter rules are placed in
app/subscription/entries/nonnative/definitions
directory. The user defined rules are provided as a zipped file asnonnative_converter_overlay_file
field of subscription manager configuration.Subscription converters output a V2Ray native outbound format, which will then be converted to a V2Ray's internal format.
Currently, embedded converter rules have limited support for different protocols and vendors. Contributions are welcome.
Subscription Converter: Nonnative converter definition format
The converters use syntax as defined by Golang Template with some additional functions to access input and process subscriptions.
To run an embedded template against a server definition input, run
v2ray engineering nonnativelinkexec -name vmess.jsont
To run an external template against a server definition input, run
v2ray engineering nonnativelinkexec -templatePath .... -name vmess.jsont
templatePath
should point to a directory with a directory nameddefinitions
with all the templates. The content of this directory can be zipped and pointed to atnonnative_converter_overlay_file
to overlay over embedded definitions.In addition to functions defined by template package, the following domain specific functions are defined.
assertExists
assertExists . key1 [key2 ...]
Checks if key1 [key2 ...] all exists in the extracted link attributes. If not, then template halt with an error.
assertIsOneOf
assertIsOneOf . key [values ...]
Check if the content of attribute[key] is one of the values. If it is not in one of the values, then template halt with an error.
assertValueIsOneOf
assertValueIsOneOf checkedValue [values ...]
Check if the checkedValue is one of the values. If it is not in one of the values, then template halt with an error.
tryGet
tryGet . key1 [key2 ...] [""]
Returns the first value found in key1 or key2... .If they are all not found and the last key is not "" then halt with an error, if he last key is "" then returns "" when nothing is found.
splitAndGetNth
splitAndGetNth sep n content
Split content with sep, and return the nth element. A negative n will be treated as
len(splited_content) + n
, If there is less than n element after split, then halt with an error.splitAndGetAfterNth
splitAndGetNth sep n content
Split content with sep, and return the nth element and elements after it. A negative n will be treated as
len(splited_content) + n
, If there is less than n element after split, then halt with an error.splitAndGetBeforeNth
splitAndGetBeforeNth sep n content
Split content with sep, and return the nth element and elements before it. A negative n will be treated as
len(splited_content) + n
, If there is less than n element after split, then halt with an error.jsonEncode
jsonEncode anyData
Return anyData encoded with json
stringCutSuffix
stringCutSuffix suffix content
Remove suffix from content's tail. If suffix is not found, halt with an error.
unalias
unalias standardName [alias...] input
if input is one of the alias return standardName, otherwise return input.
Subscription Spec: outbound format
The outbound format is the recommended subscription format for V2Ray, and what converters generates. Its
protocol
,settings
,streamSettings.transport
,streamSettings.security
,streamSettings.transportSettings
,streamSettings.securitySettings
all have the same meaning with jsonv5 format's outbound.The
metadata
is an associative array of strings.TagName
means the name of outbound tag. If it is of letters and numbers and less than 24 characters, it will be used as is and appended to user defined tag prefix as outbound's tag. Otherwise a generated one will be used.Example
Finally, here is a neat example of using subscription system with load balancing and observatory.